﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Guide
{
    public partial class EveryPage : System.Web.UI.UserControl
    {

        private List<Province> _listProvince;

        public List<Province> ListProvince
        {
            get { return _listProvince; }
            set { _listProvince = value; }
        }

        //Header 和Footer 也可以不传递 直接在这个页面 新建  赋值 也可 因为这个代表所有的每个打印页面  
        //上述叙述是错误的，需要传递啊，因为Header 和Footer 都有变量。

        private Header _header;

        public Header HeaderControl
        {
            get { return _header; }
            set { _header = value; }
        }

        private Footer _footer;

        public Footer FooterControl
        {
            get { return _footer; }
            set { _footer = value; }
        }

        private int _everyPageCount;

        public int EveryPageCount
        {
            get { return _everyPageCount; }
            set { _everyPageCount = value; }
        }

        //public string LabelContext
        //{
        //    get { return Label1.Text; }
        //    set { Label1.Text = value; }
        //}

        //public GridView GridView
        //{
        //    get { return this.GridView1; }
        //}



        protected void Page_Load(object sender, EventArgs e)
        {
            //var headerControl = (Header)LoadControl("Header.ascx");
            //headerControl.ID = "Header";
            //var footerControl = (Footer)LoadControl("Footer.ascx");
            //footerControl.ID = "Footer";
            //this.Header.Controls.Add(headerControl);
            //this.Footer.Controls.Add(footerControl);
            this.GridView2.DataSource = _listProvince;
            this.GridView2.DataBind();
            this.Header.Controls.Add(_header);
            this.Footer.Controls.Add(_footer);

        }


        //每页现实的条数
        // int totalRowCount = _everyPageCount;
        //自动填充的行数
        int autoCount = 0;

        protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                autoCount++;
            }

            if (e.Row.RowType == DataControlRowType.Footer)
            {
                int toAddCount = _everyPageCount - autoCount;
                //GridView2.BorderStyle = BorderStyle.None;
                int nunColumns = GridView2.Rows[0].Cells.Count;
                for (int i = 0; i < toAddCount; i++)
                {
                    GridViewRow row = new GridViewRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);
                    row.BorderStyle = BorderStyle.None;
                    for (int j = 0; j < nunColumns; j++)
                    {
                        TableCell cell = new TableCell();
                        cell.Text = "&nbsp;"; 
                        //cell.Text = "Hello";
                        //cell.Visible = false;
                        cell.BorderStyle = BorderStyle.None;
                        row.Cells.Add(cell);
                    }
                    GridView2.Controls[0].Controls.AddAt(autoCount + i + 1, row);

                }

            }




        }
    }
}